#ifndef _BC_Comparator_H
#define _BC_Comparator_H

/******************************************************************************
** @file	bc_communicator.h
** @author	Arturo Aguilar
** @author	Andrea Herbas
** @date	Ago 29, 2010
**
** @desc	This class compares two WinObject intances. Specifically, tells
**          if one object is equal or not to another one. We say that two 
**          are equal if both objects have the same state.
**			
**
******************************************************************************/

#include "wmi_reader.h"

template <typename T>
class BC_Comparator
{
public:
	/**
    * Compares two objects, operator == must be implemented.
    *
    * @param first object of the comparision.
    * @param second object of the comparision.
    */
    bool compare(T* t, T* t1)
    {
        return t == t1;
    }
};

template <>
class BC_Comparator<WMI_Share>
{
public:
	/**
    * Compares two WMIShare instances by its state.
    *
    * @param first share instance of the comparision.
    * @param second share instance of the comparision.
    */
    bool compare(WMI_Share* t, WMI_Share* t1)
    {
        bool equal = true;
        while(true)
        {
            if(t->getAccessMask() != t1->getAccessMask())
            {
                equal = false;
                break;
            }
            
            if(t->getAllowMaximum() != t1->getAllowMaximum())
            {
                equal = false;
                break;
            }
            if(t->getCaption() != t1->getCaption())
            {
                equal = false;
                break;
            }
            if(t->getDescription() != t1->getDescription())
            {
                equal = false;
                break;
            }
            if(t->getMaximumAllowed() != t1->getMaximumAllowed())
            {
                equal = false;
                break;
            }
            if(t->getName() != t1->getName())
            {
                equal = false;
                break;
            }
            if(t->getPath() != t1->getPath())
            {
                equal = false;
                break;
            }
            if(t->getStatus() != t1->getStatus())
            {
                equal = false;
                break;
            }
            if(t->getType() != t1->getType())
            {
                equal = false;
                break;
            }
            break;
        }
        return equal;
    }
};

template <>
class BC_Comparator<WMI_Process>
{
public:
	/**
    * Compares two WMI_Process instances by its state.
    *
    * @param first process instance of the comparision.
    * @param second process instance of the comparision.
    */
    bool compare(WMI_Process* t, WMI_Process* t1)
    {
        bool equal = true;
        while(true)
        {
            if(t->getCaption() != t1->getCaption())
            {
                equal = false;
                break;
            }

            if(t->getCommandLine() != t1->getCommandLine())
            {
                equal = false;
                break;
            }
            if(t->getCreationClassName() != t1->getCreationClassName())
            {
                equal = false;
                break;
            }
            if(t->getCSCreationClassName() != t1->getCSCreationClassName())
            {
                equal = false;
                break;
            }
            if(t->getCSName() != t1->getCSName())
            {
                equal = false;
                break;
            }
            if(t->getDescription() != t1->getDescription())
            {
                equal = false;
                break;
            }
            if(t->getExecutablePath() != t1->getExecutablePath())
            {
                equal = false;
                break;
            }
            if(t->getExecutionState() != t1->getExecutionState())
            {
                equal = false;
                break;
            }
            if(t->getHandle() != t1->getHandle())
            {
                equal = false;
                break;
            }
            if(t->getHandleCount() != t1->getHandleCount())
            {
                equal = false;
                break;
            }
            if(t->getInstallDate() != t1->getInstallDate())
            {
                equal = false;
                break;
            }
            if(t->getKernelModeTime() != t1->getKernelModeTime())
            {
                equal = false;
                break;
            }
            if(t->getMaximumWorkingSetSize() != t1->getMaximumWorkingSetSize())
            {
                equal = false;
                break;
            }
            if(t->getMinimumWorkingSetSize() != t1->getMinimumWorkingSetSize())
            {
                equal = false;
                break;
            }
            if(t->getName() != t1->getName())
            {
                equal = false;
                break;
            }
            if(t->getOSCreationClassName() != t1->getOSCreationClassName())
            {
                equal = false;
                break;
            }
            if(t->getOSName() != t1->getOSName())
            {
                equal = false;
                break;
            }
            if(t->getOtherOperationCount() != t1->getOtherOperationCount())
            {
                equal = false;
                break;
            }
            if(t->getOtherTransferCount() != t1->getOtherTransferCount())
            {
                equal = false;
                break;
            }
            if(t->getPageFaults() != t1->getPageFaults())
            {
                equal = false;
                break;
            }
            if(t->getPageFileUsage() != t1->getPageFileUsage())
            {
                equal = false;
                break;
            }
            if(t->getParentProcessId() != t1->getParentProcessId())
            {
                equal = false;
                break;
            }
            if(t->getPeakPageFileUsage() != t1->getPeakPageFileUsage())
            {
                equal = false;
                break;
            }
            if(t->getPeakVirtualSize() != t1->getPeakVirtualSize())
            {
                equal = false;
                break;
            }
            if(t->getPageFileUsage() != t1->getPageFileUsage())
            {
                equal = false;
                break;
            }
            if(t->getPeakWorkingSetSize() != t1->getPeakWorkingSetSize())
            {
                equal = false;
                break;
            }
            if(t->getPriority() != t1->getPriority())
            {
                equal = false;
                break;
            }
            if(t->getPrivatePageCount() != t1->getPrivatePageCount())
            {
                equal = false;
                break;
            }
            if(t->getProcessId() != t1->getProcessId())
            {
                equal = false;
                break;
            }
            if(t->getQuotaNonPagedPoolUsage() != t1->getQuotaNonPagedPoolUsage())
            {
                equal = false;
                break;
            }
            if(t->getQuotaPagedPoolUsage() != t1->getQuotaPagedPoolUsage())
            {
                equal = false;
                break;
            }
            if(t->getQuotaPeakNonPagedPoolUsage() != t1->getQuotaPeakNonPagedPoolUsage())
            {
                equal = false;
                break;
            }
            if(t->getQuotaPeakPagedPoolUsage() != t1->getQuotaPeakPagedPoolUsage())
            {
                equal = false;
                break;
            }
            if(t->getReadOperationCount() != t1->getReadOperationCount())
            {
                equal = false;
                break;
            }
            if(t->getReadTransferCount() != t1->getReadTransferCount())
            {
                equal = false;
                break;
            }
            if(t->getSessionId() != t1->getSessionId())
            {
                equal = false;
                break;
            }
            if(t->getStatus() != t1->getStatus())
            {
                equal = false;
                break;
            }
            if(t->getTerminationDate() != t1->getTerminationDate())
            {
                equal = false;
                break;
            }
            if(t->getThreadCount() != t1->getThreadCount())
            {
                equal = false;
                break;
            }
            if(t->getUserModeTime() != t1->getUserModeTime())
            {
                equal = false;
                break;
            }
            if(t->getVirtualSize() != t1->getVirtualSize())
            {
                equal = false;
                break;
            }
            if(t->getWindowsVersion() != t1->getWindowsVersion())
            {
                equal = false;
                break;
            }
            if(t->getWorkingSetSize() != t1->getWorkingSetSize())
            {
                equal = false;
                break;
            }
            if(t->getWriteOperationCount() != t1->getWriteOperationCount())
            {
                equal = false;
                break;
            }
            if(t->getWriteTransferCount() != t1->getWriteTransferCount())
            {
                equal = false;
                break;
            }
            break;
        }
        return equal;
    }
};

template <>
class BC_Comparator<WMI_Registry>
{
public:
	/**
    * Compares two WMI_Registry instances by its state.
    *
    * @param first registry instance of the comparision.
    * @param second registry instance of the comparision.
    */
    bool compare(WMI_Registry* t, WMI_Registry* t1)
    {
        bool equal = true;
        while(true)
        {
            if(t->getName() != t1->getName())
            {
                equal = false;
                break;
            }

            if(t->getRegistryList().size() != t1->getRegistryList().size())
            {
                equal = false;
                break;
            }
            else
            {
                for(int i = 0; i < t->getRegistryList().size(); i++)
                {
                    if(t->getRegistryList()[i]->getName() != t1->getRegistryList()[i]->getName())
                    {
                        equal = false;
                        break;
                    }
                }
            }
            break;
        }
        return equal;
    }
};

template <>
class BC_Comparator<WMI_Disk>
{
public:
	/**
    * Compares two WMI_Disk instances by its state.
    *
    * @param first disk instance of the comparision.
    * @param second disk instance of the comparision.
    */
    bool compare(WMI_Disk* t, WMI_Disk* t1)
    {
        bool equal = true;
        while(true)
        {
            if(t->getName() != t1->getName())
            {
                equal = false;
                break;
            }
            if(t->getCaption() != t1->getCaption())
            {
                equal = false;
                break;
            }
            if(t->getFileSystem() != t1->getFileSystem())
            {
                equal = false;
                break;
            }
            break;
        }
        return equal;
    }
};

template <>
class BC_Comparator<WMI_FileDirectory>
{
public:
	/**
    * Compares two WMI_FileDirectory instances by its state.
    *
    * @param first fileDirectory instance of the comparision.
    * @param second fileDirectory instance of the comparision.
    */
    bool compare(WMI_FileDirectory* t, WMI_FileDirectory* t1)
    {
        bool equal = true;
        while(true)
        {
            if(t->getCaption() != t1->getCaption())
            {
                equal = false;
                break;
            }
            if(t->getDescription() != t1->getDescription())
            {
                equal = false;
                break;
            }
            if(t->getCaption() != t1->getCaption())
            {
                equal = false;
                break;
            }
            if(t->getName() != t1->getName())
            {
                equal = false;
                break;
            }
            if(t->getStatus() != t1->getStatus())
            {
                equal = false;
                break;
            }
            if(t->getInstallDate() != t1->getInstallDate())
            {
                equal = false;
                break;
            }if(t->getCreationDate() != t1->getCreationDate())
            {
                equal = false;
                break;
            }
            if(t->getLastAccessed() != t1->getLastAccessed())
            {
                equal = false;
                break;
            }
            if(t->getLastModified() != t1->getLastModified())
            {
                equal = false;
                break;
            }
            if(t->isWriteable() != t1->isWriteable())
            {
                equal = false;
                break;
            }
            break;
        }
        return equal;
    }
};

#endif
